package cn.com.connext.scrm.repository.master;

import cn.com.connext.scrm.domain.master.BannerList;
import cn.com.connext.scrm.domain.master.PrizeCode;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import scala.Int;

import java.util.List;

/**
 * Created by yuanyajun on 2018/7/23.
 */
@Repository
public interface UploadCodeRepository extends JpaRepository<PrizeCode, Integer>, JpaSpecificationExecutor {
    @Query(value = "SELECT * FROM prize_code  WHERE  prize_good_id = :prizeGoodId and is_use IS NULL", nativeQuery = true)
    List<PrizeCode> findByPrizeGoodId(@Param("prizeGoodId") Integer prizeGoodId);
    @Query(value = "SELECT code FROM prize_code", nativeQuery = true)
    List<String> findAllCode();
    @Query(value = "SELECT * FROM `prize_code` WHERE is_use = 1 and prize_good_id = :prizeGoodId ORDER BY RAND() LIMIT 1", nativeQuery = true)
    PrizeCode findNoUseCode(@Param("prizeGoodId")Integer prizeGoodId);
    @Query(value = "SELECT * FROM prize_code where prize_good_id = :prizeGoodId and union_id = :unionId", nativeQuery = true)
    List<PrizeCode> findByGoodIdAndUnionId(@Param("prizeGoodId")Integer prizeGoodId, @Param("unionId")String unionId);
    @Query(value = "SELECT * FROM prize_code where prize_good_id = :prizeGoodId and union_id = :unionId", nativeQuery = true)
    PrizeCode findPrizeCodeByGoodIdAndUnionId(@Param("prizeGoodId")Integer prizeGoodId, @Param("unionId")String unionId);
}
